package com.ruoyi.web.controller.combat.useralignment;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.combat.domain.useralignment.CombatUserZh;
import com.ruoyi.combat.service.useralignment.ICombatUserZhService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 知乎用户信息Controller
 * 
 * @author ruoyi
 * @date 2025-03-10
 */
@RestController
@RequestMapping("/combat/userzh")
public class CombatUserZhController extends BaseController
{
    @Autowired
    private ICombatUserZhService combatUserZhService;

    /**
     * 查询知乎用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('combat:userzh:list')")
    @GetMapping("/list")
    public TableDataInfo list(CombatUserZh combatUserZh)
    {
        startPage();
        List<CombatUserZh> list = combatUserZhService.selectCombatUserZhList(combatUserZh);
        return getDataTable(list);
    }

    /**
     * 导出知乎用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('combat:userzh:export')")
    @Log(title = "知乎用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CombatUserZh combatUserZh)
    {
        List<CombatUserZh> list = combatUserZhService.selectCombatUserZhList(combatUserZh);
        ExcelUtil<CombatUserZh> util = new ExcelUtil<CombatUserZh>(CombatUserZh.class);
        util.exportExcel(response, list, "知乎用户信息数据");
    }

    /**
     * 获取知乎用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('combat:userzh:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(combatUserZhService.selectCombatUserZhById(id));
    }

    /**
     * 新增知乎用户信息
     */
    @PreAuthorize("@ss.hasPermi('combat:userzh:add')")
    @Log(title = "知乎用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CombatUserZh combatUserZh)
    {
        return toAjax(combatUserZhService.insertCombatUserZh(combatUserZh));
    }

    /**
     * 修改知乎用户信息
     */
    @PreAuthorize("@ss.hasPermi('combat:userzh:edit')")
    @Log(title = "知乎用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CombatUserZh combatUserZh)
    {
        return toAjax(combatUserZhService.updateCombatUserZh(combatUserZh));
    }

    /**
     * 删除知乎用户信息
     */
    @PreAuthorize("@ss.hasPermi('combat:userzh:remove')")
    @Log(title = "知乎用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(combatUserZhService.deleteCombatUserZhByIds(ids));
    }

    @ApiOperation(value = "多个用户信息及发布内容采集")
    @GetMapping("/Zh/{id}")
    public AjaxResult crawlZhByUserId(@PathVariable Long id) {
        combatUserZhService.crawlZhByUserId(id);
        AjaxResult ajaxResult = AjaxResult.success("采集成功");
        return ajaxResult;
    }
    @ApiOperation(value = "多个用户信息及发布内容采集")
    @GetMapping("/moreZh")
    public AjaxResult crawlZhByUserIds(@ApiParam(name = "ids", value = "需要采集的用户ids", required = true)
                                          @RequestParam(required = true) Long[] ids) {
        if (ids == null || ids.length == 0) {
            return AjaxResult.error("请传入需要采集的用户id");
        }
        combatUserZhService.crawlZhByUserIds(ids);
        AjaxResult ajaxResult = AjaxResult.success("采集成功");
        return ajaxResult;
    }

    @ApiOperation(value = "全部用户信息及发布内容采集")
    @GetMapping("/allZh")
    public AjaxResult crawlAllZhByUserIds() {
        combatUserZhService.crawlAllZhByUserIds();
        AjaxResult ajaxResult = AjaxResult.success("采集成功");
        return ajaxResult;
    }


}
